package com.kind.codegen;




import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;





public final class PropertiesManagerUtil
{
	// ----------------------------------------------------- Properties

	/**
	 * Log4J日志
	 */
	private final static Logger log =  LoggerFactory.getLogger(PropertiesManagerUtil.class);
	private static final String ORACLE_PROPERTIES = "oracle.properties";
	private static final String MYSQL_PROPERTIES = "mysql.properties";

	/**
	 * 查询配置文件属性管理对象
	 * 
	 * @return
	 */
	public static PropertiesManager getPropertiesManager(String databaseType)
	{
//		String[] properties = getPropertyConfigurer();
		PropertiesManager pm = null;
		if(databaseType.equalsIgnoreCase("mysql")){
			pm = new PropertiesManager( ReflectUtils.getResource(MYSQL_PROPERTIES));
		}else{
			pm = new PropertiesManager( ReflectUtils.getResource(ORACLE_PROPERTIES) );
		}

		return pm;
	}

	/**
	 * 查询配置文件
	 * 
	 * @return
	 */
	protected static String[] getPropertyConfigurer()
	{
		String config = System.getProperty( "bpf.config" );

		// 1.如果启动参数中包含-Dbpf.config=

		if ( StringUtils.isNoneBlank( config ))
		{
			String[] result = new String[] { config };

			for ( String e : result )
			{
				if ( log.isDebugEnabled() )
				{
					log.info( "parse load property configurer:" + e );
				}
			}

			return result;
		}
		else
		{
			if ( log.isDebugEnabled() )
			{
				log.info( "parse load property configurer as default:" + MYSQL_PROPERTIES );
			}

			return new String[] { MYSQL_PROPERTIES };
		}
	}

	
}
